# Copyright (c) 2018, the R8 project authors. Please see the AUTHORS file
# for details. All rights reserved. Use of this source code is governed by a
# BSD-style license that can be found in the LICENSE file.

import os
import utils

ANDROID_N_API = '24'
BASE = os.path.join(utils.THIRD_PARTY, 'chrome')

V180917_BASE = os.path.join(BASE, 'chrome_180917_ffbaa8')
V200430_BASE = os.path.join(BASE, 'chrome_200430')
V200520_MINIMAL_BASE = os.path.join(
    BASE, 'monochrome_public_minimal_apks', 'chrome_200520')

INPUT_JARS = [
    'out/Release/gen/chrome/android/monochrome_public_apk/monochrome_public_apk.jar',
    'out/Release/lib.java/third_party/bazel/desugar/Desugar-runtime.jar',
    'out/Release/lib.java/build/android/buildhooks/build_hooks_java.jar',
    'out/Release/lib.java/third_party/android_deps/com_android_support_support_annotations.jar',
    'out/Release/lib.java/build/android/buildhooks/build_hooks_android_java.jar',
    'out/Release/lib.java/third_party/android_deps/com_android_support_multidex_java.jar',
    'out/Release/lib.java/third_party/android_deps/android_arch_core_common.jar',
    'out/Release/lib.java/third_party/android_deps/android_arch_lifecycle_common.jar',
    'out/Release/lib.java/third_party/android_deps/android_arch_lifecycle_runtime_java.jar',
    'out/Release/lib.java/third_party/android_deps/com_android_support_support_compat_java.jar',
    'out/Release/lib.java/third_party/android_deps/com_android_support_support_core_ui_java.jar',
    'out/Release/lib.java/third_party/android_deps/com_android_support_support_core_utils_java.jar',
    'out/Release/lib.java/third_party/android_deps/com_android_support_support_fragment_java.jar',
    'out/Release/lib.java/third_party/android_deps/com_android_support_support_media_compat_java.jar',
    'out/Release/lib.java/third_party/android_deps/com_android_support_support_v4_java.jar',
    'out/Release/lib.java/third_party/jsr-305/jsr_305_javalib.jar',
    'out/Release/lib.java/base/base_java.jar',
    'out/Release/lib.java/android_webview/android_webview_commandline_java.jar',
    'out/Release/lib.java/android_webview/android_webview_platform_services_java.jar',
    'out/Release/lib.java/third_party/protobuf/protobuf_lite_javalib.jar',
    'out/Release/lib.java/android_webview/proto/aw_variations_seed_proto_java.jar',
    'out/Release/lib.java/components/variations/android/variations_java.jar',
    'out/Release/lib.java/android_webview/android_webview_variations_utils_java.jar',
    'out/Release/lib.java/components/background_task_scheduler/background_task_scheduler_task_ids_java.jar',
    'out/Release/lib.java/components/minidump_uploader/minidump_uploader_java.jar',
    'out/Release/lib.java/components/version_info/android/version_constants_java.jar',
    'out/Release/lib.java/android_webview/android_webview_services_java.jar',
    'out/Release/lib.java/components/download/public/common/public_java.jar',
    'out/Release/lib.java/ui/android/ui_utils_java.jar',
    'out/Release/lib.java/third_party/android_deps/com_android_support_support_vector_drawable_java.jar',
    'out/Release/lib.java/third_party/android_deps/com_android_support_animated_vector_drawable_java.jar',
    'out/Release/lib.java/third_party/android_deps/com_android_support_appcompat_v7_java.jar',
    'out/Release/lib.java/ui/android/ui_full_java.jar',
    'out/Release/lib.java/components/location/android/location_java.jar',
    'out/Release/lib.java/device/bluetooth/java.jar',
    'out/Release/lib.java/device/gamepad/java.jar',
    'out/Release/lib.java/device/usb/java.jar',
    'out/Release/lib.java/media/base/android/media_java.jar',
    'out/Release/lib.java/media/capture/content/android/screen_capture_java.jar',
    'out/Release/lib.java/media/capture/video/android/capture_java.jar',
    'out/Release/lib.java/media/midi/midi_java.jar',
    'out/Release/lib.java/mojo/public/java/system_java.jar',
    'out/Release/lib.java/mojo/public/java/bindings_java.jar',
    'out/Release/lib.java/mojo/public/mojom/base/base_java.jar',
    'out/Release/lib.java/ui/gfx/geometry/mojo/mojo_java.jar',
    'out/Release/lib.java/ui/gfx/mojo/mojo_java.jar',
    'out/Release/lib.java/gpu/ipc/common/gpu_preferences_interface_java.jar',
    'out/Release/lib.java/gpu/ipc/common/interfaces_java.jar',
    'out/Release/lib.java/services/service_manager/public/mojom/constants_java.jar',
    'out/Release/lib.java/services/service_manager/public/mojom/mojom_java.jar',
    'out/Release/lib.java/url/mojom/url_mojom_gurl_java.jar',
    'out/Release/lib.java/url/mojom/url_mojom_origin_java.jar',
    'out/Release/lib.java/media/mojo/interfaces/interfaces_java.jar',
    'out/Release/lib.java/mojo/public/java/system/system_impl_java.jar',
    'out/Release/lib.java/mojo/public/java/base_java.jar',
    'out/Release/lib.java/net/android/net_thread_stats_uid_java.jar',
    'out/Release/lib.java/net/android/net_java.jar',
    'out/Release/lib.java/services/device/public/mojom/constants_java.jar',
    'out/Release/lib.java/services/network/public/mojom/data_pipe_interfaces_java.jar',
    'out/Release/lib.java/services/network/public/mojom/mutable_network_traffic_annotation_interface_java.jar',
    'out/Release/lib.java/mojo/public/mojom/base/read_only_buffer_java.jar',
    'out/Release/lib.java/net/interfaces/interfaces_java.jar',
    'out/Release/lib.java/services/network/public/mojom/udp_socket_interface_java.jar',
    'out/Release/lib.java/services/network/public/mojom/websocket_mojom_java.jar',
    'out/Release/lib.java/components/content_settings/core/common/mojo_bindings_java.jar',
    'out/Release/lib.java/services/proxy_resolver/public/mojom/mojom_java.jar',
    'out/Release/lib.java/services/network/public/mojom/mojom_java.jar',
    'out/Release/lib.java/services/device/public/mojom/mojom_java.jar',
    'out/Release/lib.java/services/service_manager/public/java/service_manager_java.jar',
    'out/Release/lib.java/services/device/battery/android/battery_monitor_java.jar',
    'out/Release/lib.java/services/device/public/mojom/generic_sensor_java.jar',
    'out/Release/lib.java/services/device/generic_sensor/java.jar',
    'out/Release/lib.java/clank/third_party/android/google_play_services_basement_client.jar',
    'out/Release/lib.java/clank/third_party/android/google_play_services_tasks_client.jar',
    'out/Release/lib.java/clank/third_party/android/google_play_services_base_client.jar',
    'out/Release/lib.java/clank/third_party/android/google_play_services_location_client.jar',
    'out/Release/lib.java/services/device/public/java/geolocation_java.jar',
    'out/Release/lib.java/services/device/geolocation/geolocation_java.jar',
    'out/Release/lib.java/services/device/public/java/nfc_java.jar',
    'out/Release/lib.java/services/device/nfc/android/java.jar',
    'out/Release/lib.java/services/device/screen_orientation/java.jar',
    'out/Release/lib.java/services/device/time_zone_monitor/java.jar',
    'out/Release/lib.java/services/device/vibration/android/vibration_manager_java.jar',
    'out/Release/lib.java/services/device/wake_lock/power_save_blocker/java.jar',
    'out/Release/lib.java/services/device/java.jar',
    'out/Release/lib.java/clank/third_party/android/google_play_services_phenotype_client.jar',
    'out/Release/lib.java/clank/third_party/android/google_play_services_clearcut_client.jar',
    'out/Release/lib.java/clank/third_party/android/google_play_services_vision_common_client.jar',
    'out/Release/lib.java/clank/third_party/android/google_play_services_vision_client.jar',
    'out/Release/lib.java/skia/public/interfaces/interfaces_java.jar',
    'out/Release/lib.java/services/shape_detection/public/mojom/mojom_java.jar',
    'out/Release/lib.java/services/shape_detection/shape_detection_java.jar',
    'out/Release/lib.java/third_party/blink/public/android_mojo_bindings_java.jar',
    'out/Release/lib.java/third_party/blink/public/blink_headers_java.jar',
    'out/Release/lib.java/components/payments/mojom/mojom_java.jar',
    'out/Release/lib.java/third_party/blink/public/mojom/android_mojo_bindings_java.jar',
    'out/Release/lib.java/third_party/blink/public/mojom/speech_recognition_error_code_java.jar',
    'out/Release/lib.java/components/services/filesystem/public/interfaces/interfaces_java.jar',
    'out/Release/lib.java/device/usb/public/mojom/mojom_java.jar',
    'out/Release/lib.java/third_party/blink/public/mojom/usb/usb_java.jar',
    'out/Release/lib.java/third_party/blink/public/mojom/mojom_platform_java.jar',
    'out/Release/lib.java/third_party/blink/public/mojom/mojom_core_java.jar',
    'out/Release/lib.java/content/public/android/content_java.jar',
    'out/Release/lib.java/components/autofill/android/autofill_java.jar',
    'out/Release/lib.java/components/autofill/android/provider_java.jar',
    'out/Release/lib.java/components/crash/android/java.jar',
    'out/Release/lib.java/components/embedder_support/android/web_contents_delegate_java.jar',
    'out/Release/lib.java/components/navigation_interception/android/navigation_interception_java.jar',
    'out/Release/lib.java/components/policy/android/policy_java.jar',
    'out/Release/lib.java/components/safe_browsing/android/safe_browsing_java.jar',
    'out/Release/lib.java/components/variations/load_seed_result_enum_java.jar',
    'out/Release/lib.java/components/web_restrictions/client_java.jar',
    'out/Release/lib.java/components/spellcheck/browser/android/java.jar',
    'out/Release/lib.java/android_webview/android_webview_java.jar',
    'out/Release/lib.java/android_webview/support_library/boundary_interfaces/boundary_interface_java.jar',
    'out/Release/lib.java/android_webview/support_library/callback/callback_java.jar',
    'out/Release/lib.java/android_webview/glue/glue.jar',
    'out/Release/lib.java/android_webview/support_library/support_lib_glue_java.jar',
    'out/Release/lib.java/chrome/android/document_tab_model_info_proto_java.jar',
    'out/Release/lib.java/chrome/android/partner_location_descriptor_proto_java.jar',
    'out/Release/lib.java/chrome/android/thumbnail_cache_entry_proto_java.jar',
    'out/Release/lib.java/clank/third_party/android/google_play_services_auth_base_client.jar',
    'out/Release/lib.java/third_party/android_deps/com_android_support_palette_v7_java.jar',
    'out/Release/lib.java/third_party/android_deps/com_android_support_mediarouter_v7_java.jar',
    'out/Release/lib.java/clank/third_party/android/google_play_services_cast_client.jar',
    'out/Release/lib.java/third_party/android_deps/com_android_support_recyclerview_v7_java.jar',
    'out/Release/lib.java/clank/third_party/android/google_play_services_cast_framework_client.jar',
    'out/Release/lib.java/clank/third_party/android/google_play_services_fido_client.jar',
    'out/Release/lib.java/clank/third_party/android/google_play_services_stats_client.jar',
    'out/Release/lib.java/clank/third_party/android/google_play_services_iid_client.jar',
    'out/Release/lib.java/clank/third_party/android/google_play_services_gcm_client.jar',
    'out/Release/lib.java/chrome/android/third_party/compositor_animator/compositor_animator_java.jar',
    'out/Release/lib.java/chrome/android/webapk/libs/common/common_java.jar',
    'out/Release/lib.java/chrome/android/webapk/libs/runtime_library/webapk_service_aidl_java.jar',
    'out/Release/lib.java/chrome/android/webapk/libs/client/client_java.jar',
    'out/Release/lib.java/components/background_task_scheduler/background_task_scheduler_java.jar',
    'out/Release/lib.java/components/bookmarks/common/android/bookmarks_java.jar',
    'out/Release/lib.java/components/contextual_search/content/mojo_bindings_java.jar',
    'out/Release/lib.java/components/dom_distiller/core/android/dom_distiller_core_java.jar',
    'out/Release/lib.java/components/dom_distiller/content/browser/android/dom_distiller_content_java.jar',
    'out/Release/lib.java/components/download/internal/background_service/internal_java.jar',
    'out/Release/lib.java/components/download/public/background_service/public_java.jar',
    'out/Release/lib.java/components/embedder_support/android/content_view_java.jar',
    'out/Release/lib.java/components/feature_engagement/public/public_java.jar',
    'out/Release/lib.java/components/feature_engagement/internal/internal_java.jar',
    'out/Release/lib.java/third_party/android_tools/gcm.jar',
    'out/Release/lib.java/components/gcm_driver/android/gcm_driver_java.jar',
    'out/Release/lib.java/components/gcm_driver/instance_id/android/instance_id_driver_java.jar',
    'out/Release/lib.java/components/invalidation/impl/proto_java.jar',
    'out/Release/lib.java/components/signin/core/browser/android/java.jar',
    'out/Release/lib.java/third_party/android_protobuf/protobuf_nano_javalib.jar',
    'out/Release/lib.java/third_party/cacheinvalidation/cacheinvalidation_proto_java.jar',
    'out/Release/lib.java/third_party/cacheinvalidation/cacheinvalidation_javalib.jar',
    'out/Release/lib.java/components/sync/android/sync_java.jar',
    'out/Release/lib.java/components/invalidation/impl/java.jar',
    'out/Release/lib.java/components/offline_items_collection/core/core_java.jar',
    'out/Release/lib.java/components/payments/content/android/java.jar',
    'out/Release/lib.java/components/url_formatter/android/url_formatter_java.jar',
    'out/Release/lib.java/components/viz/service/service_java.jar',
    'out/Release/lib.java/components/web_restrictions/provider_java.jar',
    'out/Release/lib.java/printing/printing_java.jar',
    'out/Release/lib.java/services/data_decoder/public/cpp/android/safe_json_java.jar',
    'out/Release/lib.java/third_party/android_data_chart/android_data_chart_java.jar',
    'out/Release/lib.java/third_party/android_deps/javax_inject_javax_inject.jar',
    'out/Release/lib.java/third_party/android_deps/com_google_dagger_dagger.jar',
    'out/Release/lib.java/third_party/android_media/android_media_java.jar',
    'out/Release/lib.java/third_party/android_swipe_refresh/android_swipe_refresh_java.jar',
    'out/Release/lib.java/third_party/android_deps/com_android_support_transition_java.jar',
    'out/Release/lib.java/third_party/android_deps/com_android_support_design_java.jar',
    'out/Release/lib.java/third_party/android_deps/com_android_support_support_v13_java.jar',
    'out/Release/lib.java/third_party/android_deps/com_android_support_gridlayout_v7_java.jar',
    'out/Release/lib.java/third_party/custom_tabs_client/custom_tabs_support_java.jar',
    'out/Release/lib.java/third_party/gif_player/gif_player_java.jar',
    'out/Release/lib.java/third_party/leakcanary/leakcanary_noop_java.jar',
    'out/Release/lib.java/ui/base/mojo/mojo_java.jar',
    'out/Release/lib.java/third_party/feed/feed_lib_proto_java.jar',
    'out/Release/lib.java/third_party/android_deps/com_android_support_cardview_v7_java.jar',
    'out/Release/lib.java/third_party/feed/feed_lib_java.jar',
    'out/Release/lib.java/third_party/gvr-android-sdk/gvr_common_java.jar',
    'out/Release/lib.java/device/vr/java.jar',
    'out/Release/lib.java/third_party/gvr-android-keyboard/kb_java.jar',
    'out/Release/lib.java/chrome/android/chrome_java.jar',
    'out/Release/lib.java/chrome/android/monochrome_java.jar',
    'out/Release/lib.java/android_webview/platform_service_bridge_upstream_implementation_java.jar',
    'out/Release/lib.java/chrome/android/app_hooks_java.jar',
    'out/Release/lib.java/android_webview/apk/webview_license_activity_java.jar',
    'out/Release/lib.java/components/about_ui/android/aboutui_java.jar',
    'out/Release/lib.java/chrome/android/monochrome/monochrome_license_provider_java.jar',
    'out/Release/lib.java/chrome/browser/android/vr/java.jar',
    'out/Release/lib.java/third_party/arcore-android-sdk/libarcore_client_c.jar',
    'out/Release/lib.java/build/android/buildhooks/build_hooks_android_impl_java.jar'
]

PG_CONFS = [
    'out/Release/gen/chrome/android/monochrome_public_apk/monochrome_public_apk.resources.proguard.txt',
    'android_webview/apk/java/proguard.flags',
    'chrome/android/java/proguard.flags',
    'base/android/proguard/chromium_apk.flags',
    'base/android/proguard/chromium_code.flags',
    'base/android/proguard/enable_obfuscation.flags',
    'build/android/multidex.flags',
    'build/android/buildhooks/proguard/build_hooks_android_impl.flags',
    'out/Release/gen/third_party/android_deps/android_arch_lifecycle_runtime_java/proguard.txt',
    'out/Release/gen/third_party/android_deps/com_android_support_support_core_ui_java/proguard.txt',
    'out/Release/gen/third_party/android_deps/com_android_support_support_media_compat_java/proguard.txt',
    'out/Release/gen/third_party/android_deps/com_android_support_animated_vector_drawable_java/proguard.txt',
    'clank/third_party/android/javalibs/google-play-services-first-party/base_1p/proguard.txt',
    'clank/third_party/android/javalibs/google-play-services-first-party/basement_1p/proguard.txt',
    'clank/third_party/android/javalibs/google-play-services-first-party/cast-framework_1p/proguard.txt',
    'clank/third_party/android/javalibs/google-play-services-first-party/fido_1p/proguard.txt',
    'clank/third_party/android/javalibs/google-play-services-first-party/gcm_1p/proguard.txt',
    'clank/third_party/android/javalibs/google-play-services-first-party/people_1p/proguard.txt',
    'clank/third_party/android/apk_proguard.flags',
    'android_webview/support_library/boundary_interfaces/proguard.flags',
    'out/Release/gen/third_party/android_deps/com_android_support_recyclerview_v7_java/proguard.txt',
    'out/Release/gen/third_party/android_deps/com_android_support_transition_java/proguard.txt',
    'out/Release/gen/third_party/android_deps/com_android_support_design_java/proguard.txt',
    'third_party/gvr-android-sdk/src/proguard-gvr.txt',
    'third_party/gvr-android-sdk/proguard-gvr-chromium.txt',
    'third_party/arcore-android-sdk/proguard-arcore.txt',
]

LIBRARIES = [
    'third_party/android_tools/sdk/platforms/android-28/optional/org.apache.http.legacy.jar',
    'out/Release/lib.java/third_party/android_system_sdk/android_system.jar'
]

VERSIONS = {
  '180917': {
    'deploy' : {
        'r8-flags': '--no-desugaring',
        'inputs': [os.path.join(V180917_BASE, path) for path in INPUT_JARS],
        'pgconf': [os.path.join(V180917_BASE, path) for path in PG_CONFS],
        'libraries': [os.path.join(V180917_BASE, path) for path in LIBRARIES],
    },
  },
  '200430': {
    'deploy' : {
        'inputs': [os.path.join(V200430_BASE, 'program.jar')],
        'pgconf': [os.path.join(V200430_BASE, 'proguard.config')],
        'libraries': [os.path.join(V200430_BASE, 'library.jar')],
        'min-api': ANDROID_N_API
    },
  },
  '200520-monochrome_public_minimal_apks': {
    'deploy' : {
        'inputs': [os.path.join(V200520_MINIMAL_BASE, 'program.jar')],
        'features': [
            { 'inputs': [os.path.join(V200520_MINIMAL_BASE, 'feature-1.jar')] },
            { 'inputs': [os.path.join(V200520_MINIMAL_BASE, 'feature-2.jar')] },
            { 'inputs': [os.path.join(V200520_MINIMAL_BASE, 'feature-3.jar')] },
            { 'inputs': [os.path.join(V200520_MINIMAL_BASE, 'feature-4.jar')] },
            { 'inputs': [os.path.join(V200520_MINIMAL_BASE, 'feature-5.jar')] },
            { 'inputs': [os.path.join(V200520_MINIMAL_BASE, 'feature-6.jar')] },
            { 'inputs': [os.path.join(V200520_MINIMAL_BASE, 'feature-7.jar')] },
            { 'inputs': [os.path.join(V200520_MINIMAL_BASE, 'feature-8.jar')] }
        ],
        'pgconf': [os.path.join(V200520_MINIMAL_BASE, 'proguard.config'),
                   utils.IGNORE_WARNINGS_RULES],
        'libraries': [os.path.join(V200520_MINIMAL_BASE, 'library.jar')],
        'min-api': ANDROID_N_API
    },
  },
}

def GetLatestVersion():
  return '200520-monochrome_public_minimal_apks'

def GetName():
  return 'chrome'

def GetMemoryData(version):
  assert version == '200520-monochrome_public_minimal_apks'
  return {
      'find-xmx-min': 600,
      'find-xmx-max': 700,
      'find-xmx-range': 16,
      'oom-threshold': 625,
  }
